from rest_framework import serializers
from .models import MonitorParams, MonitorHost


class MonitorParamsModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = MonitorParams
        fields = ["id", "name", "description"]


class MonitorHostModelSerializer(serializers.ModelSerializer):
    host_name = serializers.CharField(source="host.name", read_only=True)
    host_ip_addr = serializers.CharField(source="host.ip_addr", read_only=True)
    host_port = serializers.CharField(source="host.port", read_only=True)
    param_name = serializers.CharField(source="param.name", read_only=True)
    param_description = serializers.CharField(source="param.description", read_only=True)

    class Meta:
        model = MonitorHost
        fields = [
            "id",
            "host",
            "host_name",
            "host_ip_addr",
            "host_port",
            "times",
            "param",
            "param_name",
            "param_description",
            "value",
            "notification_type",
            "get_notification_type_display",
            "notification_info",
        ]
